package com.vay.de.dang.online.util;

import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.widget.Toast;

public final class VnHandler {

    private static Handler uiHandler = new Handler(Looper.getMainLooper());

    public static void runUI(Runnable task) {
        if (task != null) {
            uiHandler.post(task);
        }
    }

    public static void runUIDelayed(Runnable task, long delayMillis) {
        if (task != null) {
            uiHandler.postDelayed(task, delayMillis);
        }
    }

    public static void showText(String string) {
        uiHandler.post(() -> {
            try {
                Toast.makeText(VnContext.instance().getContext(), string, Toast.LENGTH_SHORT).show();
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
    }

    public static void showText(Context context, String string) {
        uiHandler.post(() -> {
            try {
                Toast.makeText(context, string, Toast.LENGTH_SHORT).show();
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
    }
}
